#include <iostream>
#include <string>
#include <unordered_map>
#include <cmath>

std::unordered_map<std::string, int> wordsToNumbers = {
    {"zero", 0}, {"one", 1}, {"two", 2}, {"three", 3}, {"four", 4},
    {"five", 5}, {"six", 6}, {"seven", 7}, {"eight", 8}, {"nine", 9}
};

bool isPrime(int n) {
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;
    for (int i = 5; i*i <= n; i += 6) {
        if (n % i == 0 || n % (i+2) == 0)
            return false;
    }
    return true;
}

int nearestPrime(int n) {
    int smaller = n, larger = n;
    while (!isPrime(smaller) && !isPrime(larger)) {
        smaller--;
        larger++;
    }
    while (!isPrime(smaller))
        smaller--;
    while (!isPrime(larger))
        larger++;
    return (n - smaller <= larger - n) ? smaller : larger;
}

int main() {
    std::string word1, word2, word3;
    std::cin >> word1 >> word2 >> word3;

    if (wordsToNumbers.find(word1) == wordsToNumbers.end() ||
        wordsToNumbers.find(word2) == wordsToNumbers.end() ||
        wordsToNumbers.find(word3) == wordsToNumbers.end() ||
        std::isdigit(word1[0]) || std::isdigit(word2[0]) || std::isdigit(word3[0])) {
        std::cout << "Wrong input" << std::endl;
        return 0;
    }

    int number = wordsToNumbers[word1] * 100 + wordsToNumbers[word2] * 10 + wordsToNumbers[word3];
    if (number < 100 || number > 999) {
        std::cout << "Wrong input" << std::endl;
        return 0;
    }

    int prime = nearestPrime(number);
    std::cout << prime << std::endl;
    return 0;
}
